// pages/party/party.js
const util = require('../../utils/util.js');
const qiniu = require("../../utils/qiniu.min.js");
import Dialog from '../../dist/dialog/dialog';
const watch = require("../../utils/watch.js");
var WxParse = require('../../wxParse/wxParse.js');
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    orgSearch:null,
    ischange:false,
    isUser:false,
    imgid:'',
    dictValue:'',
    imgpopup:false,
    isnum:1,
    isnum1: 1,
    isnum2: 1,
    orgidflag:'',
    isptopen:false,
    auth:1,
    isBtn:true,
    orgList: [],//组织列表
    orgName: '',//组织名称
    orgUrl: '',//组织头像
    userName:'',
    avatarUrl:'',
    isOrg:false,
    list:[],
    isDele:false,
    textH:'',
    textH1:'',
    tomore:'',
    isOver:true,
    isOver1:true,
    act3:null,
    myTime:null,
    temporarilyId:'',
    isnumber:'',
    isWatch:{
      isTopic:false,
      isPerCapita:false
    },
    perCapita1:'',
    perCapita2:'',
    perCapita3:'',
    compShowed:false,
    telpShowed:false,
    seatShowed: false,
    inputShowed:false,
    isModify:false,
    isModify1: false,
    navText:'',
    topics:'',
    topics2:'',
    extras1: [],
    act2:{
      orgActType:1,
      actSigns:[],//签到信息
      isRecommend:0,
      isOrgShow:0,
      actClass: 1,//举办形式
      orgId:'',//组织id
      parts: [],//组织架构id和小组id
      sourceType: 1,//活动来源类型
      isEmail:0,
      isAddress:0,
      isIdcard:0,
      actType:'',
      id: '',
      isCustomize: '',
      extras:[],
      company: '',
      telphone: '',
      isEnrollment: 0,
      isCompany: 0,
      isTelphone: 0,
      isName: 0,
      isSex:0,
      signInWay: 0,
      seat: '',
      posterUrl: [],
      activityProcess: '',
      contents:[],
      perCapita: '',
      payer: '',
      costnum: 1,
      chooseConsume: 1,
      isCheck: 0,
      topic: '',
      actPoster: '',
      actAddress: '',
      longitude: '',
      latitude: '',
      provinceId: '',
      cityId: '',
      actStartTime: '',
      actEndTime: '',
      applyEndTime: '',
      perUpperLimit: -1,
      regimentSize: 0,
      dirty:[],
    },
    isText:false,
    ifNotice:false,
    inputRefund: '',
    singleRefund:false,
    peopelFlag: false,
    columns: [{
      values: [],
      className: 'column1'
    },
    {
      values: ['1'].concat(Array.from({
        length: 99
      }, (v, k) => k + 2)),
      className: 'column2'
    }, 
    {
      values: [],
      className: 'column5'
    }
    ],
    isCost:true,
    isOpen:false,
    // date: util.formatTime4(new Date().getTime()),
    date1: util.formatTime4(new Date().getTime()),
    disabled: false,//设置是否能点击 false可以 true不能点击
    maxLength: 12,
    currentLength: 0,
    concern: false,
    text: '关注"一起来往"公众号，及时享受活动提醒服务。',
    showMore: app.globalData.showMore,
    userInfo: '',
    showStart: false,
    currentStartDate: new Date().getTime(),
    showStartTime: false,
    currentStartTime: util.getTime(new Date()),
    minStartDate: new Date().getTime(),
    maxStartDate: new Date().getTime(),
    showEnd: false,
    currentEndDate: new Date().getTime(),
    showEndTime: false,
    currentEndTime: util.getTime(new Date()),
    maxEndDate: new Date().getTime(),
    addType: '姓名、手机号',
    remarkStr: '请设置',
    actStartTimeLong: 0,
    actStartTimeStr: util.formatTime4(new Date().getTime() + 600000),
    actEndTimeLong: 0,
    actEndTimeStr:'',
    applyEndTimeStr: '',
    applyEndTime:'',
    imgUrls: [
      '/img/pic1@2x.png'
    ],
    current: 0,
    btnText: '制作邀请函',
    getDetails:false,
    partyBack:false,
    island: false,
    loginShow:false,
  },
  
  addressInput(e){
    this.toggle('act2.actAddress', e.detail.value);
  },
  deleteArea() {
    this.toggle('act2.actAddress', '');
    this.toggle('act2.longitude', '');
    this.toggle('act2.latitude', '');
  },
  //切换组织
  isOrg(){
    this.setData({
      isOrg:true,
    })
  },
  isorghide(){
    this.setData({
      isOrg: false,
    })
  },
  orgChoice(e){
    var that = this
    var index = e.currentTarget.dataset.index
    var arr = that.data.orgList
    var actClass = e.currentTarget.dataset.actclass
    var auth = e.currentTarget.dataset.auth
    var orgSearch = e.currentTarget.dataset.orgsearch
    console.log(arr.length)
    if (actClass==1){
      that.setData({
        userName:arr[index].userName,
        avatarUrl: arr[index].avatarUrl,
        orgName: '',
        orgUrl: '',
        auth: auth,
        'act2.orgId': '',
        'act2.actClass': 1,
        'act2.orgActType': 1
      })
    }else{
      if (auth==1){
        that.setData({
          'act2.orgActType': 2
        })
      }else{
        that.setData({
          'act2.orgActType': 1
        })
      }
      if (orgSearch==0){
        that.setData({
          'act2.isRecommend': 0,
          'act2.isOrgShow': 1,
        })
      } else if (orgSearch == 1){
        that.setData({
          'act2.isRecommend': 1,
          'act2.isOrgShow': 0,
        })
      }
      that.setData({
        userName: '',
        avatarUrl: '',
        orgName: arr[index].orgName,
        orgUrl: arr[index].orgUrl,
        'act2.orgId': arr[index].orgId,
        'act2.actClass': 2,
        auth: auth,
        orgSearch: orgSearch
      })
    }
    for (var i = 0; i < arr.length;i++){
      if(i==index){
        arr[i].flag = true
      }else{
        arr[i].flag = false
      }
    }
    that.setData({
      orgList:arr,
      isOrg:false
    })
  },
  goedit(){
    if (!this.data.act2.contents.length && this.data.act2.activityProcess.length){
      wx.showToast({
        title: '此活动在官网发布或修改，请登录www.yiqilaiwang.com进行修改',
        icon:'none',
      })
    }else{
      wx.navigateTo({
        url: '/pages/edit/edit?id=' + this.data.act2.id + '&list=' + encodeURIComponent(JSON.stringify(this.data.act2.contents)) 
      })
    }
  },
  userbtn(e){
    var that = this
    var type = e.currentTarget.dataset.type
    if(type==0){
      that.setData({
        isUser: true,
        'act2.orgActType':1
      })
    } else if (type == 1){
      that.setData({
        isUser: false,
        'act2.orgActType': 2
      })
    }
  },
  //活动介绍
  bindTextAreaBlur(e) {
    this.setData({
      activityProcess: e.detail.value,
      isText:false,
      ifNotice:false
    })
    console.log('活动内容',e.detail.value)
    this.toggle('act2.activityProcess', this.data.activityProcess)
  },
  ifNotice(){
      this.setData({
        ifNotice: true,
        isText: true
      })
  },
  //选择可见人员
  gomember(){
    wx.navigateTo({
      url: '/pages/member/member?id=' + this.data.act2.orgId + "&actid=" + this.data.act2.id + "&isModify1=" + this.data.isModify1 + '&list=' + encodeURIComponent(JSON.stringify(this.data.act2.parts)) ,
    })
  },
  preventTouchMove: function (e) {
  },
  orgopenbtn(){
    var that = this
    if (that.data.orgSearch==0) {
      wx.showModal({
        content: '组织设置中的“允许组织被搜索”开关打开后，此功能才可使用',
        showCancel: false,
        confirmText: '确定',
        confirmColor: '#2168eb',
        success: function (res) {
        },
      })
    }else if (that.data.isModify1 && that.data.act2.orgOutNum>0){
        wx.showModal({
          content:'已有组织外人员报名，无法修改',
          confirmColor:'#2168EB',
          showCancel:false,
          success(res) {
            if (res.confirm) {
              console.log('用户点击确定')
            }
          }
        })
    }else{
      if (that.data.act2.isOrgShow == 0) {
        that.setData({
          'act2.isOrgShow': 1,
          'act2.isRecommend': 0,
          isptopen: false,
        })
      } else {
        that.setData({
          'act2.isOrgShow': 0,
          'act2.parts': [],
        })
      }
    }
  },
  //推荐到平台
  ptopenbtn(){
    var that = this
    if (that.data.orgSearch==0){
      wx.showModal({
        content: '组织设置中的“允许组织被搜索”开关打开后，此功能才可使用',
        showCancel: false,
        confirmText: '确定',
        confirmColor: '#2168eb',
        success: function(res) {
        },
      })
    }else if (that.data.isptopen){
      that.setData({
        isptopen: false,
        'act2.isRecommend':0,
      })
    }else{
      that.setData({
        isptopen: true,
        'act2.isRecommend': 1,
        'act2.isOrgShow': 0,
        'act2.parts':[],
      })
    }
    console.log(that.data.act2.isRecommend)
  },
  whbtn(){
    var that = this
    wx.showModal({
      // title: '推荐到平台展示',
      content: '在发现页展示：经平台审核后，平台上所有用户都可以在首页的发现页中查看、评论您所发布的内容',
      showCancel:false,
      confirmColor:"#333333",
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
        }
      }
    })
  },
  imgpopup(e){
    var that = this
    var type = e.currentTarget.dataset.type
    if(type==0){
      that.toggle('imgpopup', true);
    }else{
      that.toggle('imgpopup', false);
    }
  },
   //更换封面图片
  changeBg(e) {
    // app.TestBuriedPoint('yqlw_active_picture')
    var that = this;
    var type= e.currentTarget.dataset.type
    if(type==0){
      wx.navigateTo({
        url: '/pages/gallery/gallery?type='+that.data.act2.actType + '&id='+that.data.imgid,
      })
    }else if(type==1){
      wx.chooseImage({
        count: 1,
        sizeType: ['original', 'compressed'],
        sourceType: ['camera'],
        success: function (res) {
          const filepath = res.tempFilePaths[0]
          const src = filepath
          console.log("原地址", src)
          wx.navigateTo({
            url: `/pages/cutFace/index?src=${src}`,
          })
        }
      })
    } else if (type == 2) {
      wx.chooseImage({
        count: 1,
        sizeType: ['original', 'compressed'],
        sourceType: ['album'],
        success: function (res) {
          const filepath = res.tempFilePaths[0]
          const src = filepath
          console.log("原地址", src)
          wx.navigateTo({
            url: `/pages/cutFace/index?src=${src}`,
          })
        }
      })
    }
  },
  //活动概况图片
  posterimg() {
    var that = this;
    if (that.data.act2.posterUrl.length >= 3){
      wx.showToast({
        title: '最多只能上传3张图片',
        icon: 'none',
        duration: 2000
      })
    }else{
    app.getQiNiuToken(function (res) {
      var countnum = 3-that.data.act2.posterUrl.length
      var qiniuconfig = res;
      wx.chooseImage({
        count: countnum,
        sizeType: ['original', 'compressed'],
        sourceType: ['album', 'camera'],
        success: function (res) {
          const filepathArray = res.tempFilePaths
          for (let i = 0; i < filepathArray.length; i++) {
            qiniu.upload(filepathArray[i], res => {
              that.setData({
                posterUrl: that.data.act2.posterUrl.concat([res.imageURL])
              })
              that.toggle('act2.posterUrl', that.data.posterUrl)
              console.log("网络图片", that.data.posterUrl)
            }, (error) => {
              console.log('error' + error)
            }, {
                uploadURL: 'https://upload.qiniup.com',
                region: 'ECN',
                domain: qiniuconfig.qiniuDomain,
                uptoken: qiniuconfig.upToken,
              })
          }

        }
      })
    });
    }
  },
  delete: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    console.log('删除',index)
    that.remove(that.data.act2.posterUrl, that.data.act2.posterUrl[index]);
    that.setData({
      posterUrl: that.data.act2.posterUrl
    });
    that.toggle('act2.posterUrl', that.data.posterUrl);
    console.log('删除', that.data.act2.posterUrl)
  },
  //删除元素
  remove: function (array, val) {
    for (var i = 0; i < array.length; i++) {
      if (array[i] == val) {
        array.splice(i, 1);
      }
    }
  },
  //人员限制
  tapPeopleInput(e){
    var regimentSize = -1;
    if (e.detail.value.indexOf(".") < 0 && e.detail.value != "") {
      e.detail.value = parseFloat(e.detail.value);
    } else if (e.detail.value.indexOf(".") == 0) {
      e.detail.value = e.detail.value.replace(/[^$#$]/g, "0.");
      e.detail.value = e.detail.value.replace(/\.{2,}/g, ".");
    }
    this.setData({
      perUpperLimit: e.detail.value
    })
    this.toggle('act2.perUpperLimit', this.data.perUpperLimit);
    this.toggle('act2.regimentSize', regimentSize);
  },
  tapPeopleblur(e){
    if (this.data.act2.perUpperLimit==''){
      this.toggle('act2.perUpperLimit', -1);
    }else{
      this.toggle('act2.perUpperLimit', this.data.perUpperLimit);
    }
  },
  //第一次暂存
  FirstTemporaryStorage:function(){

    var that = this;
    var data = this.data.act2;
    this.setData({
      'act2.chooseConsume': this.data.act2.costnum
    })
      //校验地址、主题、开始结束时间必填
      if (data.topic == '' ) {
        data.topic=that.data.topics
        
      }
      if (that.data.actStartTime == '') {
        return;
      }
      if (that.data.actEndTime == '') {
        return;
      }
    if (data.perCapita == '' && data.payer == '' && data.chooseConsume != 2 && data.chooseConsume != 3) {
        return;
      }
    // if (data.actType == 8) {
    //   that.setData({
    //     chooseConsume: 3
    //   })
    //   that.toggle('act2.chooseConsume', that.data.chooseConsume)
    // }

      //校验开始时间大于当前时间
      if ( this.data.actStartTimeLong < new Date().getTime()) {
        console.log("活动开始时间校验", this.data.actStartTimeLong, new Date().getTime())
        return;
      }
      //校验开始时间小于结束时间
      if (this.data.actStartTimeLong >= this.data.actEndTimeLong) {
        console.log("活动结束时间校验", this.data.actStartTimeLong, this.data.actEndTimeLong)

        return;
      }
      //校验结束时间大于当前时间
      if (this.data.actEndTimeLong < new Date().getTime()) {
        return;
      }
      //活动报名截止日期为空则默认为活动开始时间
      if (data.applyEndTime == '') {
        data.applyEndTime = this.data.this.data.actEndTimeLong;
        console.log(data.applyEndTime);
      }

      //报名截止时间小于等于活动开始时间
    if (1 != this.data.act2.status && data.applyEndTime * 1 > this.data.actEndTimeLong) {

        return;
      }
      //将时间戳改为系统时间
      // data.applyEndTime = util.formatTime3(data.applyEndTime);
      data.actStartTime = that.data.actStartTime + ':00';
      data.actEndTime = that.data.actEndTime + ':00';
      //活动报名截止日期为空则默认为活动开始时间
      if (data.applyEndTime == '') {
        console.log("初始化截止时间");
        data.applyEndTime = data.actStartTime;
        console.log(data.applyEndTime);
      } else {
        data.applyEndTime = util.formatTime3(data.applyEndTime);
      }
      if (that.data.act2.id != ''){
        that.setData({
          id: that.data.act2.id
        })
        // that.toggle("act2.id",that.data.id)
        that.setData({
          isBtn: false,
        })
        if(that.data.isOver1){
        console.log('我是更新暂存的数据', that.data.temporarilyId,that.data.act2.id)
        app.req({
          url: 'wechat/activity/storageUpdate',
          data: that.data.act2,
          method: 'POST',
          // showLoad: true,
          success: function (res) {
            if (res.code == 200) {
              console.log('第二次暂存：')
              console.log(JSON.stringify(res))
              that.setData({
                isBtn: true,
              })
            } else {
              console.log(JSON.stringify(res))
              that.setData({
                isBtn: true,
              })
            }
          }
        })
        }else{
          that.setData({
            isBtn: true,
          })
        }
      }else{
        that.setData({
          isBtn: false,
        })
        if (that.data.isOver1) {
        console.log('我是第一次暂存的数据' + JSON.stringify(that.data.act2))
        app.req({
          url: 'wechat/activity/storageAdd',
          data: that.data.act2,
          method: 'POST',
          // showLoad: true,
          success: function (res) {
            if (res.code == 200) {
              if (that.data.temporarilyId == '') {
                console.log('第一次暂存：')
                that.setData({
                  isBtn: true,
                })
              } else {
                console.log('第二次暂存：')
                that.setData({
                  isBtn: true,
                })
              }
              console.log(JSON.stringify(res))
              that.setData({
                temporarilyId: res.data,
              })
              that.toggle("act2.id", that.data.temporarilyId)
              console.log('我是更新暂存的数据', that.data.temporarilyId, that.data.act2.id)
            }else{
              console.log('暂存报错')
              that.setData({
                isBtn: true,
              })
            }
          }
        })
        }else{
          that.setData({
            isBtn: true,
          })
        }
    }

  },

  //详情页
  tapActivityDetails(e) {
    var that = this;
    if (!that.data.island) {
      that.landbtn()
    } else {
    console.log("tapActivityDetails放法")
    // console.log("tapActivityDetails--formId==" + e.detail.formId)
    // app.TestBuriedPoint('yqlw_Active_preservation')
    getApp().mtj.trackEvent('yqlw_act_save')
    { 
      var data = that.data.act2;
      data.formId = e.detail.formId;
      var extras = []
       
      for(var i = 0 ;i <that.data.extras1.length;i++){
        var obj = {}
        obj.fields = that.data.extras1[i].fields
        obj.dataType = 'String'
        obj.isChoose =that.data.extras1[i].isChoose
        extras.push(obj)
        that.toggle('act2.extras', extras)
      }
      
        // if (data.actClass==2){
        //   that.getStructureList()
        // }
      //校验地址、主题、开始结束时间必填
      if (data.topic == '') {
        // wx.showToast({
        //   title: '请输入活动主题',
        //   icon: 'none',
        //   duration: 2000
        // })
        // return;
        // console.log('000000000000000000000000000000000000')
        data.topic = that.data.topics 
      }
      //  console.log('1111111111111111111111111111111111110')
        if (data.topic != '') {
          var num = 0
          // console.log('词库', that.data.dirty)
          for (var i = 0; i < that.data.dirty.length; i++) {
            // console.log('词库循环')
            if (data.topic.indexOf(that.data.dirty[i]) >= 0) {
              console.log('查询')
              wx.showToast({
                title: '您输入的内容有违禁词，敏感词已被替换成星号,请编辑后重新提交',
                icon: 'none',
                duration: 2000
              })
              var fw = that.data.dirty[i]
              var fw1 = ''
              for (var k = 0; k < fw.length; k++) {
                fw1 = fw1 + '*'
              }
              var topic = data.topic.replace(fw, fw1)
              console.log('替换1', topic)
              this.toggle('act2.topic', topic);
              num = num +1
            }
          }
          if(num>0){
            return;
          }
        }
      if (that.data.actStartTime == '') {
        wx.showToast({
          title: '请选择开始时间',
          icon: 'none',
          duration: 2000
        })
        return;
      }
      if (that.data.actEndTime == '') {
        wx.showToast({
          title: '请选择结束时间',
          icon: 'none',
          duration: 2000
        })
        return;
      }
        this.setData({
          'act2.chooseConsume': this.data.act2.costnum
        })
      //校验人均费用必选一个
        if (data.perCapita == '' && data.payer == '' && data.chooseConsume != 2 && data.chooseConsume != 3 && data.chooseConsume != 7) {
        wx.showToast({
          title: '请填写设置费用形式',
          icon: 'none',
          duration: 2000
        })
        return;
      }
      // if (data.actType == 8){
      //   that.setData({
      //     chooseConsume:3
      //   })
      //   that.toggle('act2.chooseConsume', that.data.chooseConsume)
      // }

      //校验开始时间大于当前时间
      if (this.data.actStartTimeLong < new Date().getTime()) {
        wx.showToast({
          title: '活动开始时间必须大于当前时间',
          icon: 'none',
          duration: 2000
        })
        return;
      }
      console.log("活动结束时间校验", this.data.actStartTimeLong, this.data.actEndTimeLong)
      //校验开始时间小于结束时间
      if (this.data.actStartTimeLong >= this.data.actEndTimeLong) {
        console.log("活动结束时间校验", this.data.actStartTimeLong ,this.data.actEndTimeLong)
        wx.showToast({
          title: '活动结束时间必须大于活动开始时间',
          icon: 'none',
          duration: 2000
        })
        return;
      }
      //校验结束时间大于当前时间
      if (this.data.actEndTimeLong < new Date().getTime()) {
        wx.showToast({
          title: '活动结束时间必须大于当前时间',
          icon: 'none',
          duration: 2000
        })
        return;
      }
        if (data.activityProcess != '') {
          var n = 0
          // console.log('词库2', this.data.dirty.length)
          for (var i = 0; i < this.data.dirty.length; i++) {
            // console.log('循环')
            if (data.activityProcess.indexOf(this.data.dirty[i]) >= 0) {
              console.log('查询2')
              wx.showToast({
                title: '您输入的内容有违禁词，敏感词已被替换成星号,请编辑后重新提交',
                icon: 'none',
                duration: 2000
              })
              var fw = this.data.dirty[i]
              var fw1 = ''
              for (var k = 0; k < fw.length; k++) {
                fw1 = fw1 + '*'
              }
              var activityProcess = data.activityProcess.replace(fw, fw1)
              console.log('替换1', activityProcess)
              this.toggle('act2.activityProcess', activityProcess);
              n= n+1
            }
          }
          if(n>0){
            return
          }
        }
        //校验需要填写信息是否保存
        if (that.data.isDele) {
          // that.setData({
          //   tomore: 'moresz',
          //   textH1: that.data.textH,
          // })
          wx.showModal({
            showCancel: false,
            content: '受邀人需填写资料为编辑状态，请保存后再试',
            success(res) {
              if (res.confirm) {
                console.log('用户点击确定')
                wx.pageScrollTo({
                  // scrollTop: textH,
                  selector: "#tomore",
                  duration: 300,
                  success: function (res) {
                    console.log('滚动成功')
                  }
                })
                // console.log('用户点击确定', that.data.tomore, that.data.textH1)
              }
            }
          })
          return;
        }
      //活动人数限制
        if (data.perUpperLimit != -1 && data.perUpperLimit<2) {
          wx.showToast({
            title: '活动人数需大于2人',
            icon: 'none',
            duration: 2000
          })
          return;
        }
        if (that.data.isModify){
          if (that.data.act2.number > data.perUpperLimit && data.perUpperLimit != -1){
            wx.showToast({
              title: '已有'+ that.data.act2.number+'人报名，人数上限不可设置为小于'+that.data.act2.number+'的数值',
              icon: 'none',
              duration: 2000
            })
            return;
          }
        }
      //活动报名截止日期为空则默认为活动开始时间
      if (data.applyEndTime == '') {
        console.log("初始化截止时间");
        data.applyEndTime = this.data.actEndTimeLong;
        console.log(data.applyEndTime);
      }

      //报名截止时间小于等于活动结束时间
        if (1 != this.data.act2.status && data.applyEndTime * 1 > this.data.actEndTimeLong) {
        wx.showToast({
          title: '报名截止时间必须小于活动结束时间',
          icon: 'none',
          duration: 2000
        })
        return;
      }
      //发起人手机号校验
      // console.log("手机号",data.telphone)
      if (data.telphone != '') {
        if (!(/^1[3465789]\d{9}$/.test(data.telphone)) || !(/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(data.telphone))) {
          wx.showToast({
            title: '请输入正确的号码格式',
            icon: 'none',
            duration: 2000
          })
          return;
        }
      }
      //将时间戳改为系统时间
      // data.applyEndTime = util.formatTime3(data.applyEndTime);
      data.actStartTime = that.data.actStartTime + ':00';
      data.actEndTime = that.data.actEndTime + ':00';
      //活动报名截止日期为空则默认为活动开始时间
      if (data.applyEndTime == '') {
        console.log("初始化截止时间");
        data.applyEndTime = data.actStartTime;
        console.log(data.applyEndTime);
      } else {
        data.applyEndTime = util.formatTime3(data.applyEndTime);
      }
      console.log(data.actStartTime);
      console.log(data.actEndTime);
      if (this.data.isOver) {
      that.setData({
        isOver:false,
        isOver1:false,
      })
      app.req({
        url: "wechat/act/roster/timeConflict",
        method: "post",
        data: {
          activityId: data.id,
          actStartTime: that.data.actStartTime,
          actEndTime: that.data.actEndTime
        },
        success: function (res) {
          console.log("请求成功");
          if (res.code == 200) {
            if (!that.data.isModify1) {
              that.addAct(data);  //发起活动接口
            } else {
              that.uptAct(data);
              console.log("更新");
              console.log(data);
            }
          } else {
            console.log("cuowu");
            console.log(data);
            if (!that.data.isModify1) {
                that.addAct(data);
              } else {
                that.uptAct(data);
              }
          }
        }
      })
      }
    }
    }
  },
  //图片点击预览
  previewImg: function (e) {
    // console.log(e.currentTarget.dataset.index);
    var index = e.currentTarget.dataset.index;
    var imgArr = this.data.act2.posterUrl;
    // console.log('图片地址', this.data.act2.posterUrl)
    // console.log(imgArr);
    wx.previewImage({
      current: imgArr[index],     //当前图片地址
      urls: imgArr,               //所有要预览的图片的地址集合 数组形式
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  //更多设置
  informationBtn(){
    var that = this
    that.setData({
       isDele:true
    })
  },
  informationBtn1(){
    var that = this
    if (that.data.list.length >0){
      app.req({
        url: "wechat/userFields/deleteFields",
        method: "post",
        data: {
          list: that.data.list
        },
        success: function (res) {
          console.log("请求成功");
          if (res.code == 200) {
            that.setData({
              isDele: false,
            })
            console.log('自定义删除')
          } else {
            wx.showToast({
              title: res.msg,
              icon: 'none',
              duration: 2000,
            })
          }
        }
      })
    }else{
      that.setData({
        isDele: false,
      })
    }

  },
  tapCheck() {
      this.setData({
        isCheck: this.data.act2.isCheck == 0 ? 1 : 0,
      })
      this.toggle('act2.isCheck', this.data.isCheck)
    if (this.data.act2.isCheck == 1) {
      app.TestBuriedPoint('yqlw_active_setup_examine')  //设置shenhe
      getApp().mtj.trackEvent('yqlw_act_check');
    }
  },
  signInWay(){
    getApp().mtj.trackEvent('yqlw_act_sign');
    wx.navigateTo({
      url: '/pages/signin/signin?actSigns=' + encodeURIComponent(JSON.stringify(this.data.act2.actSigns)) + "&longitude=" + this.data.act2.longitude + "&latitude=" + this.data.act2.latitude + "&address=" + this.data.act2.actAddress
    })
    //   this.setData({
    //     signInWay: this.data.act2.signInWay == 0 ? 1 : 0,
    //   })
    //   this.toggle('act2.signInWay', this.data.signInWay)
    // if (this.data.act2.signInWay == 1){
    //   app.TestBuriedPoint('yqlw_active_setup_signin')  //设置是否签到
    // }
  },
  isName() {
      this.setData({
        isName: this.data.act2.isName == 0 ? 1 : 0,
      })
      this.toggle('act2.isName', this.data.isName)
    if (this.data.act2.isName == 1) {
      app.TestBuriedPoint('yqlw_active_setup_name')  //设置name
    }
  },
  isSex(){
      this.setData({
        isSex: this.data.act2.isSex == 0 ? 1 : 0,
      })
      this.toggle('act2.isSex', this.data.isSex)
  },
  isTelphone() {
      this.setData({
        isTelphone: this.data.act2.isTelphone == 0 ? 1 : 0,
      })
      this.toggle('act2.isTelphone', this.data.isTelphone)
    if (this.data.act2.isTelphone == 1) {
      app.TestBuriedPoint('yqlw_active_setup_number')  //设置nmber
    }
  },
  isCompany() {
      this.setData({
        isCompany: this.data.act2.isCompany == 0 ? 1 : 0,
      })
      this.toggle('act2.isCompany', this.data.isCompany)
    if (this.data.act2.isCompany == 1) {
      app.TestBuriedPoint('yqlw_active_setup_corporatename')  //设置nmber
    }
  },
  isEnrollment() {
      this.setData({
        isEnrollment: this.data.act2.isEnrollment == 0 ? 1 : 0,
      })
      this.toggle('act2.isEnrollment', this.data.isEnrollment)
    if (this.data.act2.isEnrollment == 1) {
      app.TestBuriedPoint('yqlw_active_setup_suixingrenshu')  //设置nmber
    }
  },
  isIdcard(){
      this.setData({
        isIdcard: this.data.act2.isIdcard == 0 ? 1 : 0,
      })
      this.toggle('act2.isIdcard', this.data.isIdcard)
  },
  isAddress() {
      this.setData({
        isAddress: this.data.act2.isAddress == 0 ? 1 : 0,
      })
      this.toggle('act2.isAddress', this.data.isAddress)
  },
  isEmail() {
      this.setData({
        isEmail: this.data.act2.isEmail == 0 ? 1 : 0,
      })
      this.toggle('act2.isEmail', this.data.isEmail)
  },
  //电话号
  telphoneInput(e) {
    var telphone = e.detail.value;
    this.setData({
      telphone: telphone
    })
    this.toggle('act2.telphone', this.data.telphone)
  },
  telphoneblur(e) {
    this.setData({
      telpShowed: false
    })
    var telphone = e.detail.value

      this.setData({
        telphone: telphone
      })
    this.toggle('act2.telphone', this.data.telphone)
  },
  telpShowed(e){
    this.setData({
      telpShowed: true
    })
  },
  //组织
  companyInput(e) {
    var company = e.detail.value.replace(/\s+/g, '');
    this.setData({
      company: company
    })
    this.toggle('act2.company', this.data.company)
  },
  companyblur(e) {
    this.setData({
      compShowed: false
    })
    var company = e.detail.value.replace(/\s+/g, '')
      this.setData({
        company: company
      })
    this.toggle('act2.company', this.data.company)
  },
  compShowed(e){
    this.setData({
      compShowed: true
    })
  },
  //自定义
  cusadd(){
    app.TestBuriedPoint('yqlw_active_setup_custom')
      this.setData({
        singleRefund: true
      })
  },
  cusdelete(e) {
    var index = e.currentTarget.dataset.index;
    var id = e.currentTarget.dataset.id
    console.log('删除',index,id)
    var array = this.data.extras1
    var arr = this.data.list
    array.splice(index, 1);
    arr.push(id)
    this.setData({
      inputRefund: '',
      extras1: array,
      list:arr
    })
    console.log('list',this.data.list)
    this.toggle('act2.isCustomize',this.data.inputRefund)
  },
  inputBindSingle(e) {
    var inputRefund = e.detail.value.replace(/\s+/g, '')
    this.setData({
      inputRefund: inputRefund,
    })
    this.toggle('act2.isCustomize', this.data.inputRefund)
  },
  confirm(){
    if (this.data.inputRefund !=''){
      if (this.data.inputRefund.indexOf('姓名') >= 0 ){
       wx.showToast({
         title:'此内容已存在',
         icon:'none',
         duration: 2000,
       })
       return;
      }
      if (this.data.inputRefund.indexOf('手机号') >= 0 ) {
        wx.showToast({
          title: '此内容已存在',
          icon: 'none',
          duration: 2000,
        })
        return;
      }
      if (this.data.inputRefund.indexOf('公司名称') >= 0 ) {
        wx.showToast({
          title: '此内容已存在',
          icon: 'none',
          duration: 2000,
        })
        return;
      }
      if (this.data.inputRefund.indexOf('随行人数') >= 0 ) {
        wx.showToast({
          title: '此内容已存在',
          icon: 'none',
          duration: 2000,
        })
        return;
      }
      if (this.data.inputRefund.indexOf('身份证号') >= 0 ) {
        wx.showToast({
          title: '此内容已存在',
          icon: 'none',
          duration: 2000,
        })
        return;
      }
      if (this.data.inputRefund.indexOf('邮箱') >= 0 ) {
        wx.showToast({
          title: '此内容已存在',
          icon: 'none',
          duration: 2000,
        })
        return;
      }
      if (this.data.inputRefund.indexOf('性别') >= 0 ) {
        wx.showToast({
          title: '此内容已存在',
          icon: 'none',
          duration: 2000,
        })
        return;
      }
      for (var i =0;i<this.data.extras1.length;i++){
        if (this.data.inputRefund == this.data.extras1[i].fields){
          console.log("存在就将计就计")
          wx.showToast({
            title: '此内容已存在',
            icon: 'none',
            duration: 2000,
          })
          return;
          break;
        }
      }
      this.saveFields(this.data.inputRefund)
      console.log("zidingyi0", this.data.act2.extras,this.data.extras1)
      var extrascopy = this.data.extras1
      var obj = {}
      obj.fields = this.data.inputRefund
      obj.dataType = 'String'
      obj.isChoose = 1 
      extrascopy.push(obj)
      this.setData({
        inputRefund: this.data.inputRefund,
        singleRefund: false,
        extras: extrascopy
      })
      console.log("zidingyi", this.data.extras)
      this.toggle('act2.isCustomize', this.data.inputRefund)
      this.toggle('act2.extras', this.data.extras)
    }else{
      this.setData({
        singleRefund: false
      })
    }
  },
  //自定义选择
  cuschChoice(e){
    var index = e.currentTarget.dataset.index
    console.log('自定义选择', index)
    var arr = this.data.extras1
    arr[index].isChoose = (arr[index].isChoose == 0 ? 1 : 0)
    console.log(arr)
    this.setData({
      extras1:arr
    })
    console.log('自定义选择', e)
  },
  //保存自定义
  saveFields(name){
    var that = this
    app.req({
      url: "wechat/userFields/save",
      method: "post",
      data: {
        actType: that.data.act2.actType,
        fieldsName: name,
      },
      success: function (res) {
        console.log("请求成功");
        if (res.code == 200) {
          console.log('自定义保存', res.data, that.data.extras1)
          var arr = that.data.extras1
          var obj = res.data
          // if (!that.data.isModify1){
          //   arr.push(obj)
          // }
          that.setData({
            extras1: arr
          })
          console.log('自定义保存',that.data.extras1)
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000,
          })
        }
      }
    })
  },
  //获取自定义
  getsaveFields() {
    var that = this
    app.req({
      url: "wechat/userFields/getFields",
      method: "post",
      data: {
      },
      success: function (res) {
        console.log("请求成功");
        if (res.code == 200) {
          console.log('自定义获取')
          that.setData({
            extras1: res.data
          })
          console.log('自定义获取', that.data.extras1)
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000,
          })
        }
      }
    })
  },
  cancel(){
    this.setData({
      singleRefund:false,
      inputRefund: '',
    })
    this.toggle('act2.isCustomize', this.data.inputRefund)
    // this.toggle('act2.extras', this.data.extras)
  },
  //主题输入
  topicInput(e) {
    var topic = e.detail.value.replace(/\s+/g, ''),
      currentLength = e.detail.value.length;
      this.setData({
        topic: topic,
        currentLength: currentLength
      })
      this.toggle('act2.topic', this.data.topic);
  },
  //主题保存
  topicblur(e){
    this.setData({
      inputShowed:false,
    })
    var topic = e.detail.value.replace(/\s+/g, '')
    if (topic == ''){
      this.setData({
        topics:this.data.topics2,
      })
    }else{
      this.setData({
        topic:topic
      })
      this.toggle('act2.topic', this.data.topic);
    }
  },
//聚焦
  topicShowed(e){
    this.setData({
      inputShowed: true,
      topics:'',
    })
  },
  /**
* 日历控件绑定函数 
* 点击日期返回
*/
//开始时间
  onPickerChange: function (e) {
    //结束时间默认比开始时间晚3个小时
    var actEndTimeStr1 = new Date((e.detail.dateString).replace(/-/g, "/")).getTime() + 10800000
     var actEndTimeStr= util.formatTime4(actEndTimeStr1)
     //是否是修改活动
    if (this.data.isModify1) {
      this.setData({
        getDetails: false,
        actStartTime: e.detail.dateString,
        // isnum:this.data.isnum +1,
        // actStartTimeStr: e.detail.dateString,
        actStartTimeStr: this.data.act2.actStartTimeStr,
        applyEndTime: actEndTimeStr1,
        applyEndTimeStr: actEndTimeStr,
        actEndTimeStr: util.formatTime4(actEndTimeStr1),
        actStartTimeLong: new Date((e.detail.dateString).replace(/-/g, "/")).getTime(),
        actEndTimeLong: actEndTimeStr1
      })
    }else{
    this.setData({
      getDetails:false,
      actStartTime: e.detail.dateString,
      // isnum:this.data.isnum +1,
      actStartTimeStr: e.detail.dateString,
      // actStartTimeStr: this.data.act2.actStartTimeStr,
      applyEndTime: actEndTimeStr1,
      applyEndTimeStr: actEndTimeStr,
      actEndTimeStr: util.formatTime4(actEndTimeStr1),
      actStartTimeLong: new Date((e.detail.dateString).replace(/-/g, "/")).getTime(),
      actEndTimeLong: actEndTimeStr1 
    })
    }
    // this.toggle('act2.applyEndTime', this.data.applyEndTime)
    // this.toggle('act2.applyEndTimeStr', this.data.applyEndTimeStr)
    console.log("选中时间-------", actEndTimeStr, this.data.getDetails, this.data.isnum)
    //初始化3次后并且是修改活动
    if (this.data.isnum > 3 && this.data.isModify1){
      this.toggle('act2.actStartTimeStr', e.detail.dateString)
      this.toggle('actStartTimeStr', e.detail.dateString)
      this.toggle('act2.actEndTimeStr', actEndTimeStr)
      // this.toggle('act2.applyEndTimeStr', this.data.applyEndTimeStr)
      // this.toggle('act2.applyEndTime', this.data.applyEndTime)
      if (this.data.ischange){
        this.toggle('act2.applyEndTimeStr', actEndTimeStr)
      }
      console.log('进入时间、。。。。。。。。。' ,this.data.isModify1)
    } else if (!this.data.isModify1 || this.data.isCopy==1){//不是修改活动或者是再次发起
      this.toggle('actStartTimeStr', e.detail.dateString)
      this.toggle('applyEndTime', this.data.applyEndTime)
      this.toggle('applyEndTimeStr', this.data.applyEndTimeStr)
      // this.toggle('act2.applyEndTimeStr', this.data.applyEndTimeStr)
      this.toggle('act2.applyEndTime', this.data.applyEndTime)
    }else{
      this.toggle('isnum', this.data.isnum + 1)
    }
    console.log(e.detail.dateString)
    console.log('开始', this.data.actStartTimeLong, '结束',this.data.actEndTimeLong)
  },
  //结束时间
  onPickerChange1: function (e) {
    if (this.data.isModify1) {
      this.setData({
        actEndTime: e.detail.dateString,
        // actEndTimeStr: e.detail.dateString,
        actEndTimeStr: this.data.act2.actEndTimeStr,
        applyEndTime: new Date((e.detail.dateString).replace(/-/g, "/")).getTime(),
        applyEndTimeStr: e.detail.dateString,
        actEndTimeLong: new Date((e.detail.dateString).replace(/-/g, "/")).getTime()
      })
    }else{
      this.setData({
        actEndTime: e.detail.dateString,
        actEndTimeStr: e.detail.dateString,
        // actEndTimeStr: this.data.act2.actEndTimeStr,
        applyEndTime: new Date((e.detail.dateString).replace(/-/g, "/")).getTime(),
        applyEndTimeStr: e.detail.dateString,
        actEndTimeLong: new Date((e.detail.dateString).replace(/-/g, "/")).getTime()
      })
    }
    if (this.data.isnum1 > 3 && this.data.isModify1) {
      this.toggle('act2.actEndTimeStr', e.detail.dateString)
      if (this.data.ischange) {
        this.toggle('act2.applyEndTimeStr', e.detail.dateString)
      }
      console.log('进入结束时间、。。。。。。。。。')
    } else if (!this.data.isModify1 || this.data.isCopy == 1){
      this.toggle('actEndTimeStr', e.detail.dateString)
      this.toggle('applyEndTime', this.data.applyEndTime)
      this.toggle('applyEndTimeStr', this.data.applyEndTimeStr)
      this.toggle('act2.applyEndTime', this.data.applyEndTime)
    }else{
      this.toggle('isnum1', this.data.isnum1 + 1)
    }
  },
  //截止时间
  onPickerChange2: function (e) {
    if (this.data.isModify1){
      this.setData({
        applyEndTime: e.detail.dateString,
        applyEndTimeStr: this.data.act2.applyEndTimeStr
      })
    }else{
      this.setData({
        applyEndTime: e.detail.dateString,
        applyEndTimeStr: e.detail.dateString
      })
    }
    if (this.data.isnum2 > 3 && this.data.isModify1) {
      this.toggle('act2.applyEndTime', this.data.applyEndTime)
      this.toggle('act2.applyEndTimeStr', e.detail.dateString)
      console.log('进入截止时间、。。。。。。。。。')
    } else if (!this.data.isModify1 || this.data.isCopy == 1){
      this.toggle('applyEndTimeStr', e.detail.dateString)
      this.toggle('applyEndTime', this.data.applyEndTime)
      this.toggle('act2.applyEndTime', this.data.applyEndTime)
    }else{
      this.toggle('isnum2', this.data.isnum2 + 1)
    }
    console.log('截止时间',this.data.applyEndTimeStr)
  },
  //开始时间事件
  openStartDate() {
    this.setData({
      showStart: true
    })
  },
  openGPS() {
    var that = this;
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.userLocation']) {
          wx.authorize({
            scope: 'scope.userLocation',
            success: function() {
              that.realOpenGPS();
            },
            fail: function(d) {
              wx.showModal({
                title: '获取授权失败',
                content: '是否前往设置允许小程序使用位置信息',
                success(res) {
                  if (res.confirm) {
                    wx.openSetting({
                      complete: function(r) {
                        if (r.authSetting['scope.userLocation']) {
                          that.realOpenGPS();
                        }
                      }
                    });
                  }
                }
              })
            }
          })
        } else {
          that.realOpenGPS();
        }
      }
    });
  },
  //聚会地点
  realOpenGPS() {
    var that = this;
    wx.chooseLocation({
      success: function(res) {
        that.toggle('act2.actAddress', res.name);
        that.toggle('act2.longitude', res.longitude);
        that.toggle('act2.latitude', res.latitude);
        that.toggle('act2.actAddress2', res.address);
      },
      fail(res) {
        console.log(res)
      }
    });
  },
  //设置席位
  seatInput(e) {
    var seat = e.detail.value.replace(/\s+/g, '');
    this.setData({
      seat: seat
    })
    console.log('房间', this.data.seat)
    this.toggle('act2.seat', this.data.seat)
  },
  seatblur(e){
    this.setData({
      seatShowed: false
    })
    var seat = e.detail.value.replace(/\s+/g, '')
    if (seat == ''){
      this.setData({
        seat:''
      })
    }else{
      this.setData({
        seat: seat
      })
    }
    this.toggle('act2.seat', this.data.seat);
  },
  //聚焦
  seatShowed(e){
    this.setData({
      seatShowed: true
    })
  },
  //人均费用
  setFee() {
    var that = this
    if(that.data.isModify1){
      app.req({
        url: 'wechat/activity/getAllJoinMember',
        data: {
          activityId: that.data.act2.id
        },
        method: 'POST',
        success: function (res) {
          if (res.data > 0) {
            wx.showToast({
              title: '由于有人已经报名缴费，所以费用不可修改',
              icon: 'none',
              duration: 2000
            })
          }else{
            that.setData({
              isCost: false
            })
          }
        }
      })
    }else{
      that.setData({
        isCost: false
      })
    }
  },
  //费用
  costoption1(e) {
    var id = e.currentTarget.dataset.index
    console.log(id)
    this.setData({
      costnum:id,
    })
    if(id !=2){
      this.setData({
        payer:""
      })
      this.toggle('act2.payer', this.data.payer)
    }
     if(id != 1){
      this.setData({
        perCapita1:''
      })
    }
     if(id !=5){
      this.setData({
        perCapita3: ""
      })
    } 
   if (id != 8) {
      this.setData({
        perCapita2: ""
      })
    }
    this.toggle('act2.costnum', this.data.costnum)
    // this.toggle('act2.chooseConsume', this.data.costnum)
  },
  //人均,会费，公益
  percapitaInput1(e) {
    e.detail.value = e.detail.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    e.detail.value = e.detail.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');

    if (e.detail.value.indexOf(".") < 0 && e.detail.value != "") {
      e.detail.value = parseFloat(e.detail.value);
    } else if (e.detail.value.indexOf(".") == 0) {
      e.detail.value = e.detail.value.replace(/[^$#$]/g, "0.");
      e.detail.value = e.detail.value.replace(/\.{2,}/g, ".");
    }
    if (e.detail.value > 500000) {
      e.detail.value = 500000
    }
    this.setData({
      perCapita1: e.detail.value
    })
    // this.toggle('act2.perCapita', this.data.perCapita)
  },
  percapitaInput2(e) {
    e.detail.value = e.detail.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    e.detail.value = e.detail.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');

    if (e.detail.value.indexOf(".") < 0 && e.detail.value != "") {
      e.detail.value = parseFloat(e.detail.value);
    } else if (e.detail.value.indexOf(".") == 0) {
      e.detail.value = e.detail.value.replace(/[^$#$]/g, "0.");
      e.detail.value = e.detail.value.replace(/\.{2,}/g, ".");
    }
    if (e.detail.value > 500000) {
      e.detail.value = 500000
    }
    this.setData({
      perCapita2: e.detail.value,
    })
    // this.toggle('act2.perCapita', this.data.perCapita)
  },
  percapitaInput3(e) {
    e.detail.value = e.detail.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    e.detail.value = e.detail.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');

    if (e.detail.value.indexOf(".") < 0 && e.detail.value != "") {
      e.detail.value = parseFloat(e.detail.value);
    } else if (e.detail.value.indexOf(".") == 0) {
      e.detail.value = e.detail.value.replace(/[^$#$]/g, "0.");
      e.detail.value = e.detail.value.replace(/\.{2,}/g, ".");
    }
    if (e.detail.value > 500000) {
      e.detail.value = 500000
    }
    this.setData({
      perCapita3: e.detail.value
    })
    // this.toggle('act2.perCapita', this.data.perCapita)
  },
  //请客
  treatInput(e) {
    var payer = e.detail.value
    this.setData({
      payer: payer,
    })
    this.toggle('act2.payer', this.data.payer);
  },
  costok(e){
    // this.setData({
    //   chooseConsume:this.data.act2.costnum
    // })
    if (this.data.act2.costnum == 1){
      getApp().mtj.trackEvent('yqlw_act_cost_aa');
    } else if(this.data.act2.costnum == 2){
      getApp().mtj.trackEvent('yqlw_act_cost_treat');
    } else if (this.data.act2.costnum == 3) {
      getApp().mtj.trackEvent('yqlw_act_cost_free');
    }
    if (this.data.act2.costnum == 1 && this.data.perCapita1 == ''){
      wx.showToast({
        title: '请填写人均费用',
        icon: 'none',
        duration: 2000
      })
    } else if (this.data.act2.costnum == 1 && this.data.perCapita1 == 0){
      wx.showToast({
        title: '人均费用应大于0',
        icon: 'none',
        duration: 2000
      })
    } else if (this.data.act2.costnum == 1 && this.data.perCapita1 < 0.01) {
      wx.showToast({
        title: '最小金额为0.01',
        icon: 'none',
        duration: 2000
      })
    } else if (this.data.act2.costnum == 5 && this.data.perCapita3 == '') {
      wx.showToast({
        title: '请填写指定金额',
        icon: 'none',
        duration: 2000
      })
    } else if (this.data.act2.costnum == 5 && this.data.perCapita3 == 0) {
      wx.showToast({
        title: '金额应大于0',
        icon: 'none',
        duration: 2000
      })
    } else if (this.data.act2.costnum == 5 && this.data.perCapita3 < 0.01) {
      wx.showToast({
        title: '最小金额为0.01',
        icon: 'none',
        duration: 2000
      })
    } else if (this.data.act2.costnum == 8 && this.data.perCapita2 == '') {
      wx.showToast({
        title: '请填写指定金额',
        icon: 'none',
        duration: 2000
      })
    } else if (this.data.act2.costnum == 8 && this.data.perCapita2 == 0) {
      wx.showToast({
        title: '金额应大于0',
        icon: 'none',
        duration: 2000
      })
    } else if (this.data.act2.costnum == 8 && this.data.perCapita2 < 0.01) {
      wx.showToast({
        title: '最小金额为0.01',
        icon: 'none',
        duration: 2000
      })
    } else if (this.data.act2.costnum == 2 && this.data.act2.payer == ''){
      wx.showToast({
        title: '请填写请客人',
        icon: 'none',
        duration: 2000
      })
    }else{
      if (this.data.perCapita1){
        this.toggle('act2.perCapita', this.data.perCapita1)
      } else if (this.data.perCapita2){
        this.toggle('act2.perCapita', this.data.perCapita2)
      } else if (this.data.perCapita3){
        this.toggle('act2.perCapita', this.data.perCapita3)
      }
      this.setData({
        isCost:true,
        isnumber:1,
      })
    }
    // this.toggle('act2.chooseConsume', this.data.chooseConsume)

    //埋点
    if (this.data.act2.costnum == 1){
      app.TestBuriedPoint('yqlw_active_cost_aa')
    } else if (this.data.act2.costnum == 2){
      app.TestBuriedPoint('yqlw_active_cost_Treat')
    } else if (this.data.act2.costnum == 3){
      app.TestBuriedPoint('yqlw_active_cost_gratis')
    } else if (this.data.act2.costnum == 4){
      app.TestBuriedPoint('yqlw_active_cost_cashgif')
    } else if (this.data.act2.costnum == 5){
      app.TestBuriedPoint('yqlw_active_cost_charitable')
      app.TestBuriedPoint('yqlw_active_cost_voluntarily')
    } else if (this.data.act2.costnum == 6){
      app.TestBuriedPoint('yqlw_active_cost_nothing')
    }


  },
  costno(e){
    this.setData({
      isCost: true
    })
  },
  onClose: function() {
    this.setData({
      // showPay: false,
    });
  },
  addAct(actData) {
    console.log('我是发起活动的数据：' + JSON.stringify(actData))
    var that = this;
    app.req({
      url: 'wechat/activity/addActivity',
      data: actData,
      method: 'POST',
      showLoad: true,
      success: function(res) {
        if (res.code == 200) {
         that.setData({
           isOver:true
         })
          console.log("我是发起活动的数据--"+res.data.id)
          wx.navigateTo({
            url: '/pages/register/register?id=' + res.data.id
          });
          if(that.data.auth==1){
            wx.showToast({
              title: '活动已创建成功',
              duration: 2000
            })
          } else if (that.data.auth == 0){
            wx.showToast({
              title: '您的活动已提交'+that.data.orgName+'审核，请耐心等待',
              duration: 3000,
              icon:'none'
            })
          }
          
        } else {
          that.setData({
            isOver: true
          })
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  uptAct(actData) {
    var that = this
    console.log('uptact:'+JSON.stringify(actData))
    app.req({
      url: 'wechat/activity/updateActivity',
      data: actData,
      method: 'POST',
      showLoad: true,
      success: function(res) {
        console.log('resresresres:'+JSON.stringify(res))
        if (res.code == 200) {
          that.setData({
            isOver: true
          })
          // wx.navigateTo({
          //   url: '/pages/register/register?isBack=1&id=' + res.data.id
          // });
          wx.navigateBack({
            delta: 1
          })
        } else {
          that.setData({
            isOver: true
          })
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  //获得默认背景图
  getBgImgList(img) {
    var that = this;
    // app.req({
    //   url: 'wechat/image/list',
    //   data: {
    //     "type": that.data.act2.actType
    //   },
    //   method: 'POST',
    //   success: function(res) {
    //     if (res.code == 200) {
    //        console.log('背景图',res)
    //       for( var i = 0 ;i< res.data.length ; i++){
    //         if(res.data[i].sort ==1){
    //           that.setData({
    //            actPoster:res.data[i].url,
    //             topics: res.data[i].remark,
    //             topics2: res.data[i].remark
    //           })
    //           that.toggle('act2.actPoster', that.data.actPoster)
    //         }
    //       }
    //     } else {
    //       wx.showToast({
    //         title: res.msg,
    //         icon: 'none',
    //         duration: 2000
    //       })
    //     }
    //   }
    // })
    app.req({
      url: "wechat/activity/listByDictType",
      method: "post",
      data: {
        dictType: "IS_OPEN_STATE",
        dictName: that.data.act2.actType
      },
      success: function (res) {
        if (200 == res.code) {
          console.log("获取相册列表", res)
          that.setData({
                topics: res.data.remark,
                topics2: res.data.remark,
                imgid: res.data.headPictureId,
                dictValue: res.data.dictValue
              })
          that.toggle('act2.actPoster', res.data.headPicture)
          wx.hideLoading()
        } else {
          wx.hideLoading()
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  //获得活动详情
  getActInfo(id, isCopy) {
    var that = this;
    app.req({
      url: 'wechat/activity/activityDetail',
      data: {
        "id": id
      },
      method: 'POST',
      success: function(res) {
        if (res.code == 200) {
          var data = res.data,
            startDate = util.formatDate(data.actStartTime),
            endDate = util.formatDate(data.actEndTime),
            applyEndDate = util.formatDate(data.applyEndTime),
            count = data.isSex + data.isWechatNum + data.isIdcard + (data.isCusromize == '' ? 0 : 1);
          data.applyEndTimeStr = util.formatTime4(applyEndDate);
          if (isCopy == 1) {
            data.id = '';
            data.status = -1;
            startDate = util.formatTime4(new Date().getTime() + 600000)
            endDate = util.formatTime4(new Date().getTime() + 11400000)
            data.applyEndTimeStr = util.formatTime4(new Date().getTime() + 11400000)
            data.applyEndTime = util.formatTime4(new Date().getTime() + 11400000)+':00'
          }
          console.log('再次发起', endDate, data.applyEndTimeStr, data.applyEndTime)
          var startEndDate = new Date(startDate), End2Date = new Date(endDate);
          startEndDate.setFullYear(startEndDate.getFullYear() + 1);
          End2Date.setFullYear(End2Date.getFullYear() + 1);
          if (res.data.actClass==2){
            that.setData({
              orgName: res.data.orgName,
              orgUrl: res.data.orgUrl,
              userName:'',
              avatarUrl:'',
            })
          }
          that.setData({
            act2: data,
            topic:data.topic,
            'act2.costnum':data.chooseConsume,
            currentStartDate: startDate,
            currentStartTime: util.getTime(startDate),
            maxStartDate: startEndDate.getTime(),
            currentEndDate: endDate,
            currentEndTime: util.getTime(endDate),
            maxEndDate: End2Date.getTime(),
            addType: '姓名、手机号' + (count > 0 ? '等' : ''),
            remarkStr: data.remark == '' ? '请设置' : util.subRemark(data.remark),
            actStartTimeLong: startDate,
            actEndTimeLong: endDate,
            btnText: '完成',
            getDetails:true,
            extras1: res.data.extras,
          });
          WxParse.wxParse('activityProcess', 'html', that.data.act2.activityProcess, that, 5);
          if(that.data.isModify1){
          if(util.formatTime4(endDate) == util.formatTime4(applyEndDate)){
            that.setData({
              ischange:true
            })
            }
            that.setData({
              'act2.actStartTimeStr': util.formatTime4(startDate),
              'act2.actEndTimeStr': util.formatTime4(endDate),
              'act2.applyEndTimeStr': util.formatTime4(applyEndDate),
            })
          }
          var actType = res.data.actType
           console.log('导航栏', actType)
          if (actType == 1) {
            wx.setNavigationBarTitle({
              title: '团购'
            })
          } else if (actType == 2) {
            wx.setNavigationBarTitle({
              title: '打游戏'
            })
          } else if (actType == 3) {
            wx.setNavigationBarTitle({
              title: '运动'
            })
          }
          else if (actType == 4) {
            wx.setNavigationBarTitle({
              title: '宴请'
            })
          } else if (actType == 5) {
            wx.setNavigationBarTitle({
              title: '团建'
            })
          } else if (actType == 6) {
            wx.setNavigationBarTitle({
              title: '婚礼'
            })
          } else if (actType == 7) {
            wx.setNavigationBarTitle({
              title: '大型活动'
            })
          } else if (actType == 8) {
            wx.setNavigationBarTitle({
              title: '会议'
            })
          } else if (actType == 9) {
            wx.setNavigationBarTitle({
              title: '商家活动'
            })
          } else if (actType == 10) {
            wx.setNavigationBarTitle({
              title: '社团活动'
            })
          } else if (actType == 11) {
            wx.setNavigationBarTitle({
              title: '公益'
            })
          }
          // that.getBgImgList(data.actPoster);
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  //是否关注公众号
  concernWechat: function() {
    var that = this;
    app.req({
      url: "wechat/sys/register",
      method: "post",
      success: function(res) {
        // that.toggle("concern", !!res);
      }
    });
  },
  //获取组织列表
  getorgList(){
    var that = this;
    app.req({
      url: "wechat/org/orgList",
      method: "post",
      success: function (res) {
       if(res.code==200){
         if (that.data.orgidflag){
           for(let item in res.data){
             if (res.data[item].orgId == that.data.orgidflag){
               res.data[item].flag = true
             }
           }
           that.setData({
             orgList: res.data,
           })
         }else{
           for (let item in res.data) {
             if (res.data[item].id== '1') {
               res.data[item].flag = true
             }
           }
           that.setData({
             orgList: res.data,
           })
         }
         console.log('组织列表',that.data.orgList.length)
       }
      }
    });
  },
  getdirty(){
    var that = this
    app.req({
      url: "wechat/dirty/all",
      method: "post",
      success: function (res) {
        if (res.code == 200) {
          wx.setStorageSync('dirty', res.data);
          // console.log('脏字啦啦啦啦啦', res.data)
              that.setData({
                dirty:res.data
              })
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // watch.setWatcher(this)  //监听
    var that = this;
    if (options.name || options.theme || options.type){
      that.setData({
        navText: options.name,
        // topic: options.theme,
        // topics: options.theme,
        actType: options.type
      })
      that.toggle('act2.actType', that.data.actType)
    }
    wx.setNavigationBarTitle({
      title: that.data.navText
    })
    that.getdirty()
    app.getUserInfo(function(userInfo) {
      that.setData({
        userInfo: userInfo
      })
      that.concernWechat();
    })
    if (options.id && options.id != '') {
      that.getActInfo(options.id, options.isCopy);
    } else {
      that.getBgImgList();
    }
    if (options.isModify==1){
      that.setData({
        isModify:true,
      })
    }
    if (options.isModify1 == 1) {
      that.setData({
        isModify1: true,
      })
    }else{
      that.getsaveFields()
      console.log('开始时间', that.data.actStartTimeStr)
      that.setData({
        actStartTimeStr: util.formatTime4(new Date().getTime() + 600000)
      })
    }
    if (options.orgid) {
      app.req({
        url: "wechat/org/orgList",
        method: "post",
        success: function (res) {
          if (res.code == 200) {
            for (var i = 0; i < res.data.length; i++) {
              if (res.data[i].orgId == options.orgid) {
                that.setData({
                  orgidflag: options.orgid,
                  'act2.actClass': 2,
                  orgName: res.data[i].orgName,
                  orgUrl: res.data[i].orgUrl,
                  avatarUrl: '',
                  userName: '',
                  'act2.orgId': options.orgid
                })
              }
            }
          }
        }
      });
    }else{
      that.setData({
        userName:that.data.userInfo.nickName,
        avatarUrl:that.data.userInfo.avatarUrl
      })
    }
    let pages = getCurrentPages();
    let prevpage = pages[pages.length - 2];
    console.log("是从哪个页面来的" + prevpage.route)

    // if (options.actPoster) {

    // }
    //页面高度
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var textH = clientHeight * rpxR -158;
         console.log('祝福高度2', that.data.textH)
        that.setData({
          textH: textH
        });
      }
    });
    // if (wx.getStorageSync('dirty') == undefined || wx.getStorageSync('dirty') == ''){
      // that.getdirty()
    // }else{
    //   that.setData({
    //     dirty: wx.getStorageSync('dirty')
    //   });
    // }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  onHide:function(){
    var that = this
    clearInterval(that.data.myTime)
  },
  onUnload(){
    var that = this
    clearInterval(that.data.myTime)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this
    if (that.data.partyBack) {
      console.log("从这里返回的首页")
      wx.reLaunch({
        url: '/pages/index/index'
      })
    }
    wx.getSetting({
      success: (res) => {
        console.log('授权', res)
        if (wx.getStorageSync('uid')) {
          that.setData({
            island: true
          })
          //获取头像及名称
          app.getUserInfo(function (userInfo) {
            that.toggle("userInfo", userInfo);
            console.log('已授权登陆', userInfo)
            if (that.data.orgName==''&& that.data.orgUrl==''){
              that.setData({
                userName: that.data.userInfo.nickName,
                avatarUrl: that.data.userInfo.avatarUrl
              })
            }
          })
        }else{
          that.landbtn()
        }
      }
    })
    app.TestBuriedPoint('yqlw_active_pv')
    var startDate = new Date(), startEndDate = new Date();
    startEndDate.setFullYear(startEndDate.getFullYear() + 1);
    this.setData({
      currentStartDate: startDate.getTime(),
      currentStartTime: util.getTime(startDate),
      maxStartDate: startEndDate.getTime(),
      imgpopup:false
    })


    clearInterval(that.data.myTime);
    if(!that.data.isModify1){
      that.timeFunction()
    }
    that.getorgList()
    WxParse.wxParse('activityProcess', 'html', that.data.act2.activityProcess, that, 5);
  },
  timeFunction: function(){
    var that = this
    that.setData({
      myTime: setInterval(function () {
        console.log('延时器：')
        that.FirstTemporaryStorage()
      }, 10000)
    })
    

  },
  // 登录
  landbtn() {
    this.toggle('loginShow', true)
    this.selectComponent('#login').showClose()
  },
  toggleToast(e) {
    console.log(e.detail)
    if (!e.detail.loginShow){
      this.toggle('loginShow', false)
    }
    this.onShow()
  },

})